﻿//===============================================================================
//	Player.h
//	用户类
//===============================================================================

#pragma once

#include <mutex>
#include <string>
#include <stdint.h>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include "../../3rd/libjson/json.h"
#include "../share/MessageDef.h"
#include "Role.h"
#include "PlayerDataStruct.h"
#include "UIntArray.h"
#include "PropertyDefine.h"
#include "LuaManager.h"

#include "PlayerTemporaryDataDefinition.h"
#include "Vector2D.h"
#include "TempValue.h"
#include "../share/object.h"
#include "role_activity.h"
#include "role_fightsquare.h"
#include "passivity_skill.h"
#include "Fixed1024.h"
#include "RuntimeData.h"


using namespace boost::property_tree;

class BaseMessage;

//class CCheckAccountRet;
//class CPlayerRegisterRet;
//class CPlayerLoginRet;
class CPlayerAttack;
class CUpdatePlayerInfo;
class CGeneralJsonStringRet;
class CLoseBlood;
class CSomeoneDead;
class LuaManager;

//class RewardData;
//class MissionSystem;
//class MissionDialogue;
//class NoticeCommon;
#include "Mission.h"
#include "MissionDialogue.h"
#include "RewardData.h"
#include "NoticeCommon.h"
#include "NoticeCommonEx.h"
#include "Backpack.h"
#include "TitleSystem.h"
#include "RedPointDefine.h"
#include "continueRecharge.h"
#include "entity.h"

class CKick;
class CPing;
class CEnterScene;
class CLeaveScene;
class CAskMissionList;
class CAskMissionComplete;
class COpenMissionDialog;
class CNoticeCommon;
class COpenRewardDialogue;
class CNoticeCommonEx;
class CTitleList;
class CTitleTakeOffOrWear;
class CAskMissionBoxInfo;
class CAskOfferRewardMissionList;
class CUpdateMissionItemInfo;
class CGuideInfo;
class CUIAction;
class CUpdateSpecifiedBufferPart;
class CWildDigOperation;
class CFixed1024Info;
class CServerInitFinished;
class CGetRankListInfo;
class CAskDailyMissionList;
class CErrMessage;
class CRelayMessage;
class CPlayerMove;
class CTwGroupIdNotifyRet;

class CAskBranchMissionList;

class GDGeneralMessage;

class PlayerCommon;	//	用户通用属性

class CZeroBlood;

class CChatMessageGeneralPush;
class CChatMessageGeneralRet;
class CChatToFriendMessageRet;
class CChatFriendMessageGeneralPush;

/************************************
 *	玩家获得称号类型定义
 *	! 该类型对应称号脚本id，不可更改*/
enum e_title_type_name
{
	title_refill = 20000,
	title_total = 20001,
	title_level = 20002,
	title_moba_rank = 20003,
	title_level_rank = 20004,
	title_fc_rank = 20005,
};

enum class PlayerState : int32_t
{
	ps_pre_enter_scene,
	ps_in_scene,
	ps_normal,
	ps_dead,
};

static const uint32_t player_key_start = 4200000000;//	uint32最大4294967295

class Player
	: public Role, public CEntity
{
	static const uint32_t size_1024 = 1024;
	static const uint32_t title_state_size = 32;
	static const uint32_t title_state_start = 512;	//索引位置 = id + idx
	static const uint32_t title_state_end = title_state_start + title_state_size;
	static const uint32_t max_property_count = 17;	//最大属性条目数量
	static const uint32_t max_special_title_count = 10;
	static const uint32_t max_hero_count = 120;		// 最大英雄个数
public:
	enum EPlayerState
	{
		STATE_UNKNOWN = 0,
		STATE_LOADING = 1,//数据库加载
		STATE_GAME = 2,//游戏中
		STATE_WATT_DESTROY = 3, // 等待被销毁
	};
private:

	std::recursive_mutex							m_player_mutex;
	std::recursive_mutex							m_sync_redis2mysql;

	std::vector<uint32_t>				m_tmp_who_can_see_me;
	PlayerFixedIntegerArray				m_Buffer;

	PlayerRuntimeInfo*					m_runtime_info;
	PlayerCommon*						m_property;

	lua_manager_ptr						m_player_lua_ptr;
	Vector2D							m_now_pos;
	Vector2D							m_now_direct;
	TempValue							m_temp_value;
	uint64_t							m_last_pos_caculate_time;
	uint32_t							m_PlayerId;
	int32_t								m_socket_id;			//	socket ID
	double								m_CurTitleProperty[max_property_count];
	uint32_t							m_TitleGetTime[max_special_title_count];
	MissionSystem						m_missionSys;
	MissionDialogue						m_missionDlg;
	RewardData							m_playerReward;
	NoticeCommon						m_notice;
	uint32_t							m_update_info_flag;
	uint32_t							m_update_fixed_flag;
	uint32_t							m_update_info_my_flag;
	NoticeCommonEx						m_notice_ex;
	Backpack							m_backpack;
	TitleSystem							m_titleSys;

	// --
	char								m_Name[32];				// 昵称
	char								m_UnionName[64];		// 工会名称

	uint32_t							m_Account;				// 帐号
	uint32_t							m_Area;					// 所在游戏区
	uint32_t							m_Photo;				// 头像ID
	uint32_t							m_PhotoFrame;			// 头像框ID
	uint32_t							m_Exps;					// 当前经验值
	uint32_t							m_MaxExps;				// 当前最大经验值
	uint32_t							m_Level;				// 当前等级
	uint32_t							m_HeroId;				// 当前英雄ID
	uint32_t							m_HeroSkinId;			// 当前英雄皮肤ID
	uint32_t							m_Vip;					// VIP等级
	uint32_t							m_VipExps;				// VIP经验
	uint32_t							m_UnionId;				// 工会ID
	uint32_t							m_UnionPosition;		// 工会职位
	uint32_t							m_Afc;					// 战队战斗力
	std::string							m_wtUnionGroupId;		// 触宝公会组ID

	uint32_t							m_Thew;					// 体力
	
	uint32_t							m_SkillPoint;			// 技能点
	uint32_t							m_SkillPointTime;		// 技能点20点满点时间

	uint32_t							m_OnlineReward;			// 在线奖励
	uint32_t							m_TDining;				// 定时进餐计数
	uint32_t							m_SoulDraw;				// 魂匣抽奖计数
	uint32_t							m_GoldDraw;				// 金币抽奖计数
	uint32_t							m_DiamondDraw;			// 钻石抽奖计数-
	uint32_t							m_ChangeName;			// 修改昵称计数
	uint32_t							m_OnlineTime;			// 在线时长
	uint32_t							m_MaxRank;				// 角斗场最大排行
	uint32_t							m_GoldRevive;			// 日金币复活次数
	uint32_t							m_DiamondRevive;		// 日钻石复活次数
	uint32_t							m_BuyThew;				// 购买体力计数
	uint32_t							m_PassedTime;			// heartbeat过去的时间
	uint32_t							m_ExpsPool;				// 英雄经验池
	uint32_t							m_PetId;				// 出战宠物ID
	uint32_t							m_MountsId;				// 骑乘坐骑ID
	uint32_t							m_MountState;			// 坐骑骑乘状态: 0: 未骑乘, 1:骑乘
	uint32_t							m_CurrHeroLevel;		// 当前出阵英雄等级
	uint32_t							m_DefPetId;				// 默认设定宠物ID
	uint32_t							m_DefMountsId;			// 默认设定坐骑ID
	uint32_t							m_Newbie;				// 是否新手
	uint32_t							m_NewbieFlag;			// 1:新号注册/0:登录
	uint32_t							m_MaxThewTime;			// 恢复至最大体力时间点

	uint32_t							m_FirstRechargeState;	// 首次充值状态 0无记录 1未领取 2已领取
	uint32_t							m_ForeverCard;			// 永久卡状态 0未购买 1已购买
	uint32_t							m_MonthCard;			// 月卡终止日期状态 170630
	int32_t							m_ForeverCardRewardState;  //终身卡领取状态
	uint32_t							m_client_scene_id;			//为客户端场景准备的场景id 

	PlayerState							m_player_state;

	std::string							m_Guide;				// 功能引导列表
	std::string							m_FightHero;			// 出战英雄列表
	std::string							m_AdFightHero;			// 竞技场防守英雄列表
	std::string							m_Ed1FightHero;			// 活动副本1英雄列表
	std::string							m_Ed2FightHero;			// 活动副本2英雄列表
	std::string							m_Ed3FightHero;			// 活动副本3英雄列表
	std::string							m_Ed4FightHero;			// 活动副本4英雄列表
	std::string							m_Ed5FightHero;			// 活动副本5英雄列表
	std::string							m_ArenaFightHero;		// 竞技场进攻英雄列表
	std::string							m_ThroneFightHero;		// 王座进攻英雄列表
	std::string							m_ExpeditionFightHero;  // 远征进攻英雄列表
	std::string							m_MiniFightHero;		// 4人普通副本英雄列表

	std::string							m_FuncList;				// 开放功能列表
	std::string							m_SceneList;			// 开发场景列表
	std::string							m_DotBuffer;			// 

	std::string							m_TitleList;			// 称号ID列表
	std::string							m_GrooveShop;			// 杂货店
	std::string							m_EliteShop;			// 精英商店
	std::string							m_MysteryShop;			// 神秘商店
	std::string							m_PveShop;				// 远征商店
	std::string							m_PvpShop;				// 竞技场商店
	std::string							m_UnionShop;			// 工会商店
	std::string							m_ArenaShop;			// 角斗场商店
	std::string							m_RewardShop;			// 悬赏商店
	std::string							m_NewbieReward;			// 新手15天礼包

	std::string							m_DaySigned;			// 每日签到
	std::string							m_EventDungeon;			// 活动副本
	std::string							m_EdDayInfo;			// 活动副本战斗日记录
	std::string							m_LvReward;				// 等级奖励

	std::string							m_DailyTask;			// 日常任务列表

	std::string							m_RechargeList;			// 充值列表计数
	std::string							m_VipGiftBox;			// VIP特权礼包领取记录

	uint32_t							m_achievementLevel;		//成就等级
	uint32_t							m_allServiceAchievementRanking;		//成就等级

	double								m_pos_x;
	double								m_pos_y;
	double								m_pos_z;
	
	CContinueRecharge	m_continueRecharge;		// 续充

public:
	void SetachievementLevel(uint32_t _m_achievementLevel) {
		m_achievementLevel = _m_achievementLevel;
	}
	void SetallServiceAchievementRanking(uint32_t _m_allServiceAchievementRanking) {
		m_allServiceAchievementRanking = _m_allServiceAchievementRanking;
	}


private:

	PlayerHero							m_playerHero[max_hero_count];
	uint32_t							m_HerosCount;

	uint32_t							m_HeartBeatCount;
	uint32_t							m_RecoverThewCount;

private:
	//MissionBranch*						m_branch_mission;

private:
	//protocol
	CKick*								m_kick;
	CPing*								m_ping;
	//CNotify*							m_notify;
	CEnterScene*						m_enter_scene;
	CLeaveScene*						m_leave_scene;
	CPlayerAttack*						m_player_attack;
	CUpdatePlayerInfo*					m_update_player_info;
	CLoseBlood*							m_lose_blood;
	CSomeoneDead*						m_someone_dead;
	CAskMissionList*					m_ask_mission_list;
	CAskMissionComplete*				m_ask_mission_list_complete;
	COpenMissionDialog*					m_open_mission_dlg;
	CNoticeCommon*						m_notice_common;
	COpenRewardDialogue*				m_open_reward_dlg;
	CNoticeCommonEx*					m_notice_common_ex;
	CTitleList*							m_title_list;
	CTitleTakeOffOrWear*				m_title_takeoff_wear;
	CGeneralJsonStringRet*				m_GeneralJsonStringRet;
	CTwGroupIdNotifyRet*				m_tw_group_id_notify;
	CAskMissionBoxInfo*					m_mission_box_info;
	CAskOfferRewardMissionList*			m_offer_reward_mission_list;

	CUpdateMissionItemInfo*				m_update_mission_item_ret;
	CGuideInfo*							m_guide_info;
	CUIAction*							m_ui_action;
	CUpdateSpecifiedBufferPart*			m_update_specified_buffer_part;
	CWildDigOperation*					m_wild_dig_operation;
	CFixed1024Info*						m_fixed_1024_info;
	CServerInitFinished*				m_server_init_finished;
	CGetRankListInfo*					m_get_rank_list;
	CAskDailyMissionList*				m_ask_daily_mission_list_ret;
	//CPlayerLoadSceneFinished*			m_player_load_scene_finished;
	CErrMessage*						m_player_err_ret;
	CRelayMessage*						m_relay_message;
	CPlayerMove*						m_player_move;
	CAskBranchMissionList*				m_ask_branch_mission_list_ret;

	GDGeneralMessage*					m_gd_general_message_notify;

	CZeroBlood*							m_target_zero_blood_notify;

	CChatMessageGeneralPush*			m_chat_message_general_push;
	CChatMessageGeneralRet*				m_chat_message_general_ret;
	CChatToFriendMessageRet*			m_chat_firend_message_ret;
	CChatFriendMessageGeneralPush*		m_chat_friend_message_push;


private:
	void createSocketMessage(void);
	void deleteSocketMessage(void);
	void updatePlayerInfo(void);

	void clearPlayerInfo(void);
	void sendPlayerLoadSceneFinished(void);

	void loadSceneFinished(void);

	void recoverPlayerThew(void);

public:

	static const uint32_t name_str_len = 32;
	static const uint32_t fixed_part_pos_count = 16;

public:
	Player(void);
	~Player(void);

public:
	// 通过 Role 继承
	virtual void Heartbeat(uint32_t passTime = 0) override final;
	virtual void Update(uint32_t passTime = 0) override final;

	virtual void TickUpdate();
public:
//	LuaManager*	GetLuaState();

	void GetFixed1024InfoByErea(uint32_t startPos, uint32_t endPos);
	EPlayerState player_state() const { return player_state_; }
	void set_player_state(EPlayerState player_state) { player_state_ = player_state; }

	bool ReadDataFromJson(Json::Value& jsonplayer);
	bool ReadDataFromPtree ( boost::property_tree::ptree && ptree );
	bool WriteDataToJson(Json::Value& jsonplayer);
public:
	//---------------------------------------------------------------------------
	void Send2CEnterScene(uint32_t sceneId, double posX, double posY, double posZ);
	void Send2CLevelScene(uint32_t sceneId);


	void SyncMyRedisData2Mysql();
	//---------------------------------------------------------------------------
	void KickPlayerNotify(uint32_t);

	//---------------------------------------------------------------------------
	//	fixed_1024

	void SetFixedBitValue(uint16_t idx, uint16_t start, uint16_t size, uint32_t val);
	int32_t GetFixedBitValue(uint16_t idx, uint16_t start, uint16_t size);
	void SetFixedValue(uint16_t idx, uint32_t val);
	int32_t GetFixedValue(uint16_t idx);
	uint32_t GetFixedPosValueByIndex(uint16_t idx);

	void AddFixedValue(uint16_t idx, uint32_t val);
	void ReduceFixedValue(uint16_t idx, uint32_t val);

	//---------------------------------------------------------------------------
	//	walk
	void SendToClient(std::string* str, uint32_t msgId = 0);
	void SendToClient(const char* msg, uint32_t msgId = 0);
	void SendToClient(Json::Value& msg, uint32_t msgId);
	//void UpdateNewPosition(double posX, double posY, double posZ);

	void SendToDBServer(std::string* str, uint32_t msgId = 0);

	// lcl 2017-11-23 时间刷新调用lua
	void update_by_time(lua_manager_ptr lua_ptr,unsigned int label_id);

	//---------------------------------------------------------------------------
	//	chat
	void PushChatMessageToClient(uint32_t type, const char*, uint32_t, uint32_t, uint32_t, uint32_t, const char*
		, uint32_t horn = 0, uint32_t shareType = 0);
	void PushChatMessageToClient(uint32_t type, const char*, uint32_t, uint32_t, uint32_t, uint32_t, const char*
		, const char*, double, const char*);
	void SaveChatRecord(uint32_t, uint32_t, const char*, Player&, uint16_t	hornType = 0, uint16_t shareType = 0);
	void SaveChatRecord(uint32_t, uint32_t, const char*, Player&, const char*, double, const char*);
	void SendChatRetMessageToClient(uint16_t retVal = 0);
	void SendGmMarqueeToClient(uint32_t spn, uint32_t tp, std::string msg, std::string playerName, uint32_t priority = 1);

	void SendFriendChatRetMessageToClient(uint32_t, uint32_t, uint16_t retVal = 0);

	void PushChatMessageToFriendClient(uint32_t type, const char*, uint32_t, uint32_t, uint32_t
		, uint32_t, const char*, uint32_t, uint32_t);
	void PushChatMessageToFriendClient(uint32_t type, const char*, uint32_t, uint32_t, uint32_t
		, uint32_t, const char*, uint32_t, uint32_t, const char*, double, const char*);

	void getChatMessageJson(std::string& chatstr, uint32_t type, const char*, uint32_t, uint32_t, uint32_t
		, uint32_t, const char*, uint32_t, uint32_t, const char*, double, const char*);

	//---------------------------------------------------------------------------
	//	任务相关
	MissionSystem* GetMissionSystem(void);
	MissionDialogue* GetMissionDialogue(void);
	RewardData* GetRewardData(void);
	NoticeCommon* GetNoticeData(void);
	PlayerFixedIntegerArray* GetMissionState(void);
	NoticeCommonEx* GetNoticeExData(void);

	// 任务列表
	void GetMissionCompleteState();
	void GetMissionList();
	void SendMissionDialogueToClient(void);
	void SendRewardDataToClient(void);
	void SendNoticeCommonToClient(void);
	void GetMissionBoxInfoToClient(void);
	void GetOfferRewardMissionListToClient(void);
	void UpdateOfferRewardMissionNewList(void);
	void UpdateOfferRewardMissionListByOneItem();

	// 任务+
	// 列表
	void AskOfferRewardMissionList(void);
	void AskDailyMissionList(void);
	void SendDailyMissionList(void);
	uint32_t CheckUnlockedMissionInDailyList(uint32_t missionId);
	// 数据
	void SetDailyMissionData(std::string strData);
	std::string GetDailyMissionData(void);

	std::string GetDailyMissionData( std::string const & strMissionDate );

	// 支线任务
	// ...任务系统待优化

	// 任务过程
	void KillMonsterMainMission(uint32_t monsterId);
	void ClickNpc(uint32_t npcId, uint32_t paramFirst, uint32_t paramSecond);
	void CollectMission(uint32_t itemId, uint32_t allCount);//不进背包
	void CheckMissionByItemChanged(void);//背包物品
	void MoveToPositionMisson(uint32_t missionId, uint32_t posX, uint32_t posZ);
	//void KillMonsterMission(uint32_t missionId, uint32_t monsterId, uint32_t allCount);//protocol test !
	//void DungeonMission(uint32_t missionId, uint32_t dungeonId, uint32_t result);
	void DungeonMission(uint32_t dungeonId);
	void SendNoticeCommonExToClient(void);
	void OperationOfferRewardMission(uint32_t missionPos, uint32_t type);
	//void UpdateMainMissionStateByPlayerLevel(void);
	void UpdateMissionItemInfo(uint32_t index);

	// 野外任务
	void WildDeliveryDone(void);
	void WildCollet(uint32_t itemId);
	void WildDeliveryMoveToNpc(uint32_t npcId, uint32_t npcX, uint32_t npcY);
	void KillMonsterWildMission(uint32_t monsterId);

	//---------------------------------------------------------------------------
	//杀(人、怪物)与被杀
	void Bekilled(uint32_t whoId = 0);
	void KilledSomeone(MapElement* tar);
	void TargetZeroBloodNotify(uint32_t tarId);


	//---------------------------------------------------------------------------
	// 帐号检查
	void SendCheckAccountRetToClient(void);

	//---------------------------------------------------------------------------
	// 聊天消息通知
	void SendPlayerChatMessageNotifyToClient(uint32_t types, std::string& notify_info,
		uint32_t chat_time, uint32_t destAccountId = 0);

	//---------------------------------------------------------------------------
	// 更新角色背包中某些物品及数量
	void SendPlayerUpdateItemListRetToClient(std::string& info);

	//---------------------------------------------------------------------------
	// 用户工会信息更改通知
	void SendPlayerUnionInfoChangedNotifyToClient(uint32_t types, uint32_t unionId,
		uint32_t unionPosition, std::string& unionName);// , std::string& twGroupId);

	//---------------------------------------------------------------------------
	// 发送触宝组ID改变通知
	void TW_SendGroupIdNotify(uint32_t types, std::string& groupId);

	//---------------------------------------------------------------------------
	// 更新角色宠物信息
	void SendPlayerUpdatePetListRetToClient(std::string& info);

	// 更新角色坐骑信息
	void SendPlayerUpdateMountsListRetToClient(std::string& info);

	// 更新增加用户英雄信息
	void SendPlayerUpdateHeroListRetToClient(std::string& info, int32_t types, int32_t topFc);

	//---------------------------------------------------------------------------
	//	玩家信息

	uint32_t GetSocketId(void);
	void SetSocketId(int32_t socketId);

	void SetName(const char* v);
	char* GetName(void);

	void SetUnionName(const char* v);
	char* GetUnionName(void);

	// 游戏货币
	void SetCurrency(uint16_t idx, uint32_t v);
	uint32_t GetCurrency(uint16_t idx);

	void SetPingTime(uint32_t ch, uint32_t cl);
	bool CheckPingTime(void);


	void SetDungeonStar(int32_t idx, int32_t v);

	//void SetLastDungeonId(int32_t v);
	int32_t GetLastDungeonId(void);

	//玩家武将
	//void SetPlayerRankHeroDataPosUsed(int32_t idx, bool v);
	int32_t GetPlayerRankHeroDataUsablePos(void);
	void SetPlayerRankHeroId(int32_t idx, int32_t v);
	void SetPlayerRankHeroLv(int32_t idx, int32_t v);
	void SetPlayerRankHeroStars(int32_t idx, int32_t v);
	void SetPlayerRankHeroPhoto(int32_t idx, int32_t v);
	void SetPlayerRankHeroFc(int32_t idx, int32_t v);
	void SetPlayerRankHeroName(int32_t idx, const char* name);

	access_variable(uint32_t,	Account,		m_Account);					// 帐号
	access_variable(uint32_t,	PlayerId,		m_PlayerId);				// 帐号
	access_variable(uint32_t,	Area,			m_Area);					// 所在游戏区
	access_variable(uint32_t,	Photo,			m_Photo);					// 头像ID

	//access_variable(uint32_t,	Exps,			m_Exps);					// 当前经验值
	access_variable(uint32_t,	MaxExps,		m_MaxExps);					// 当前最大经验值
	access_variable(uint32_t,	VipExps,		m_VipExps);					// VIP经验
	access_variable(uint32_t,	UnionId,		m_UnionId);
	access_variable(std::string,WtUnionGroupId, m_wtUnionGroupId);			// 公会触宝组ID
	access_variable(uint32_t,	UnionPosition,	m_UnionPosition);

	access_variable(uint32_t,	TDining ,		m_TDining);
//	access_variable(uint32_t,	Thew,			m_Thew);					// 体力
	access_variable(uint32_t,	OnlineReward,	m_OnlineReward);			// 在线奖励
	access_variable(uint32_t,	SkillPoint,		m_SkillPoint);				// 技能点

	access_variable(uint32_t,	SkillPointTime, m_SkillPointTime);			// 技能点20点满点时间

	access_variable(uint32_t,	SoulDraw,		m_SoulDraw);				// 魂匣抽奖计数
	access_variable(uint32_t,	GoldDraw,		m_GoldDraw);				// 金币抽奖计数
	access_variable(uint32_t,	DiamondDraw,	m_DiamondDraw);				// 钻石抽奖计数
	access_variable(uint32_t,	ChangeName,		m_ChangeName);				// 修改昵称计数
	access_variable(uint32_t,	OnlineTime,		m_OnlineTime);				// 在线时长
	access_variable(uint32_t,	MaxRank,		m_MaxRank);					// 角斗场最大排行

	access_variable(uint32_t,	GoldRevive,		m_GoldRevive);				// 日金币复活次数
	access_variable(uint32_t,	DiamondRevive,	m_DiamondRevive);			// 日钻石复活次数

	access_variable(uint32_t,	BuyThew,		m_BuyThew);
	access_variable(uint32_t,	PassedTime,		m_PassedTime);				// heartbeat过去的时间
	
	access_variable(uint32_t,	ExpsPool,		m_ExpsPool);				// 经验池
	//access_variable(uint32_t,	PetId,			m_PetId);					// 宠物ID
	//access_variable(uint32_t,	MountsId,		m_MountsId);				// 坐骑ID
	//access_variable(uint32_t,	MountsState,	m_MountState);				// 坐骑骑乘状态
	access_variable(uint32_t,	CurrHeroLevel,	m_CurrHeroLevel);			// 当前出阵英雄等级
	access_variable(uint32_t,	DefPetId,		m_DefPetId);
	access_variable(uint32_t,	DefMountsId,	m_DefMountsId);

	access_variable(uint32_t,	NewbieFlag,		m_NewbieFlag);

	access_variable(uint32_t,	MaxThewTime,	m_MaxThewTime);				// 恢复至最大体力时间点

	access_variable(uint32_t,	FirstRechargeState, m_FirstRechargeState);

	access_variable(uint32_t, ForeverCard, m_ForeverCard);
	access_variable(uint32_t, MonthCard, m_MonthCard);

	access_variable( int32_t, ForeverCardRewardState, m_ForeverCardRewardState );	

	access_variable(PlayerState, PlayerState,	m_player_state);		

//	access_variable(std::string, TitleList,		m_TitleList);

	access_variable(std::string, DaySigned,		m_DaySigned);
//	access_variable(std::string, FuncList,		m_FuncList);
	access_variable(std::string, SceneList,		m_SceneList);
	access_variable(std::string, DotBuffer,		m_DotBuffer);

	access_variable(std::string, Guide,			m_Guide);

	access_variable(std::string, FightHero,		m_FightHero);
	access_variable(std::string, AdFightHero,	m_AdFightHero);
	access_variable(std::string, Ed1FightHero,	m_Ed1FightHero);
	access_variable(std::string, Ed2FightHero,	m_Ed2FightHero);
	access_variable(std::string, Ed3FightHero,	m_Ed3FightHero);
	access_variable(std::string, Ed4FightHero,	m_Ed4FightHero);
	access_variable(std::string, Ed5FightHero,	m_Ed5FightHero);
	access_variable(std::string, ArenaFightHero, m_ArenaFightHero);
	access_variable(std::string, ThroneFightHero, m_ThroneFightHero);
	access_variable(std::string, ExpeditionFightHero, m_ExpeditionFightHero);
	access_variable(std::string, MiniFightHero, m_MiniFightHero);

	access_variable(std::string, GrooveShop,	m_GrooveShop);	
	access_variable(std::string, EliteShop,		m_EliteShop);
	access_variable(std::string, MysteryShop,	m_MysteryShop);
	access_variable(std::string, PveShop,		m_PveShop);
	access_variable(std::string, PvpShop,		m_PvpShop);
	access_variable(std::string, UnionShop,		m_UnionShop);
	access_variable(std::string, ArenaShop,		m_ArenaShop);
	access_variable(std::string, RewardShop,	m_RewardShop);

	access_variable(std::string, NewbieReward,	m_NewbieReward);
	access_variable(std::string, EventDungeon,	m_EventDungeon);
	access_variable(std::string, EdDayInfo,		m_EdDayInfo);
	access_variable(std::string, LvReward,		m_LvReward);

	access_variable(std::string, DailyTask, m_DailyTask);

	access_variable(std::string, RechargeList, m_RechargeList);
	access_variable(std::string, VipGiftBox, m_VipGiftBox);

	access_variable(lua_manager_ptr, PlayerLuaState,	m_player_lua_ptr);

	access_variable(uint32_t, SceneClientId, m_client_scene_id);

	access_variable(double, PosX, m_pos_x);
	access_variable(double, PosY, m_pos_y);
	access_variable(double, PosZ, m_pos_z);

// access_variable
	void SetThew(uint32_t);
	uint32_t GetThew() { return m_Thew; }

	void SetLevel(int32_t level);
	int32_t GetLevel() { return m_Level; }

	void SetAfc(int32_t afc);
	int32_t GetAfc() { return m_Afc; }

	void SetHeroId(uint32_t heroid);
	uint32_t GetHeroId() { return m_HeroId; }

	void SetHeroSkinId(uint32_t heroskinid);
	uint32_t GetHeroSkinId() { return m_HeroSkinId; }

	void SetVip(int32_t vip);
	int32_t GetVip() { return m_Vip; }

	void SetPhotoFrame(uint32_t photoframe);
	uint32_t GetPhotoFrame() { return m_PhotoFrame; }

	void SetFuncList(std::string _val);
	std::string GetFuncList(void);

	void SetUpdateInfoFlag(UpdatePlayerInfoType uit);
	uint32_t GetUpdateInfoFlag(void);
	void ClearUpdateInfoFlag(void);

	void SetUpdateInfoMyFlag(UpdatePlayerInfoType uit);
	uint32_t GetUpdateInfoMyFlag(void);
	void ClearUpdateInfoMyFlag(void);

	void SetExps(uint32_t exps);
	uint32_t GetExps() { return m_Exps; }
						// 宠物ID
	uint32_t GetPetId() { return m_PetId; }
	void SetPetId(uint32_t pet_id);
	uint32_t GetMountsId() { return m_MountsId; }				// 坐骑ID
	void SetMountsId(uint32_t mount_id);
	uint32_t GetMountsState() { return m_MountState; }
	void SetMountsState(uint32_t state);


	//void AddBackpackItemToRedisDB(const std::string& jvStr);

	PlayerRuntimeInfo* GetPlayerRuntimeInfo(void){ return m_runtime_info; }

	// ping 更新玩家数据
	void UpdatePlayerInfoPing();



public:

	// 英雄
	PlayerHero* GetAllHeroInfo(uint32_t& size);

	PlayerHero* GetPlayerHeroEmptyPos();
	// 根据ID获得某英雄信息
	PlayerHero* GetPlayerHeroInfoByID(uint32_t heroId);

	// 初始化设置英雄所有属性
	void GetOneHeroInfo(uint32_t heroId, PlayerHero& heroData);
	void SetOneHeroInfo(uint32_t heroId, Json::Value jm);

	// reset 不重置英雄ID，名称和UUID
	void ResetOneHeroInfo(uint32_t heroId, Json::Value jm);

	std::string GetDailyTaskDate();

	void SendToMapUpdateHeroInfo(uint32_t heroid, Json::Value& jm, uint32_t set_type);
public:
	//---------------------------------------------------------------------------

	

	//---------------------------------------------------------------------------
	//void UpdateFixed1024ValueByIndexToClient(uint32_t idx
	//	, uint32_t bitIdx, uint32_t len, uint32_t val);

	//---------------------------------------------------------------------------
	//	称号 
	//---------------------------------------------------------------------------
	//	称号表id从1开始 [1024]存储结构称号状态索引与id对应
	//	title state

	TitleSystem* GetTitleSystem(void);
	uint32_t GetWearingTitleId(void);
	void GetTitleList(void);
	void WearOrTakeOffTitle(uint32_t titleId, uint32_t oprType);
	void SendTakeOffOrWearTitleToClient(int32_t ret, uint32_t titleId, uint32_t oprType);
	//void GetPlayerTitleByType(uint32_t titleType, uint32_t paramCount, uint32_t itemType = 0);//20002, 1默认 itemType:单项类型


	//---------------------------------------------------------------------------
	//	背包
	int16_t GetItemCountByItemId(uint32_t id);

	//---------------------------------------------------------------------------
	//	野外:挖宝
	void OpenWildDig(void);
	void SendWildDigPoints(const char* idStr, uint32_t sceneId);

	//---------------------------------------------------------------------------
	//	奖励
	void GetDailyMissionRewardProps(uint32_t missionId, uint32_t firsrPram, uint32_t secondPram);
	void GetActiveRewardBox(uint32_t activeBoxId, uint32_t boxLv, uint32_t param);
	void GetWildDiaReward(void);


	//---------------------------------------------------------------------------
	//	转换场景
	void ChangeScene(int32_t flag, uint32_t to, uint32_t from = 0);

	//	前端红点
	void SetRedPointNotify(std::string rpp);

	//---------------------------------------------------------------------------
	//	关于属性的设置与读取
	double GetProperty(int32_t heroId, property_type pt);
	void SetTitleProperty(int16_t idx, property_type pt, double val);

	//---------------------------------------------------------------------------
	//	引导相关信息传输
	void SendGuideInfo(uint32_t scriptId, int32_t typeId, 
		int32_t stepId, uint32_t widgetId);

	//	 控制前端界面开启关闭
	void ManipulateSpecifiedUI(uint32_t UIId, int32_t Action);



	//---------------------------------------------------------------------------
	//	缓冲区（1024）指定内容到客户端
	void SpecifiedBufferPartStart(void);
	void AddBufferDate(uint16_t idx);
	void SpecifiedBufferPartEnd(void);
	void SendSpecifiedBufferPart(void);

	//---------------------------------------------------------------------------
	//	存储fixed1024
	void SavePlayerFixedInfo(void);
	void SetFixedSdtSaveFlagByPos(uint16_t pos);

	//---------------------------------------------------------------------------
	//	存储指定位置的fixed1024 pos 1~16
	void SaveSinglePlayerFixedInfo(uint32_t pos, bool bSaveToDB=false);
	//	获取sdt段信息
	void GetSinglePlayerFixedInfo(uint32_t, std::string&);

	// 一次性存储fixed1024
	void SaveAllPlayerFixedInfo(bool bSaveToDB);


	//	发送服务器的player信息初始化完成
	void SendServerInitFinished(void);


	bool SetPlayerSomeInfoToRedisDB(std::string field, std::string value, uint32_t bTable);
	void SetPlayerSomeInfoToRedisDB(std::string field, int32_t value);


	//	取得主英雄属性参数
	HeroProperty* GetMainHeroProperty(void);


	// 检查可发送的系统邮件
	void CheckSystemMailToSend(void);

	//	清除摇杆状态
	void ClearRockerState(void);

	//	GM
	void GmCurrentMainMission(uint32_t);

public:
	// 角色数据存储
	void PlayerSave();
	void set_login_key(int32_t login_key) { mlogin_key = login_key; }
	int32_t login_key() { return mlogin_key; }
	void set_connected(bool connected) { connected_ = connected; }
	void OnDisconnect();
	void OnNewDay();
	void OnNewZeroDay();
	void OnNewWeek();
	void OnNewMonth();

	bool PlayerInGame();
	int32_t GetLastSaveTime() { return last_save_time_; }
	int32_t RefreshLastSaveTime();
	

	//消耗玩家数值
	int32_t ChangeNumber(int32_t type,int32_t value);

	void SaveToJson(Json::Value& detail_data);
	void LoadFromJson(Json::Value& detail_data);
	void set_update_time(int32_t cur_sec) { update_time_ = cur_sec; }

	void FillBaseInfoToJson(Json::Value& player_json);
	//同步game玩家到map玩家
	void SyncPlayer2MapByFlag(int32_t flag);


	static void BroadcastSelfPlayer(Player & player, uint32_t flag = 0);
private:
	EPlayerState player_state_;
	int32_t mlogin_key;
	bool connected_;
	int32_t disconnect_time_;
	int32_t m_ping_time;		// 最后一次ping时间
	int32_t update_time_;
	int32_t last_save_time_;

public:
	CRoleActivity& role_activity() { return role_activity_; }
	CRoleFightSquare& role_square() { return role_fight_square_; }
	PassivitySkill& passivity_skill() { return passivity_skill_; }
private:
	CRoleActivity role_activity_;	//活动次数管理
	CRoleFightSquare role_fight_square_;//队伍阵型
	PassivitySkill passivity_skill_;	// 被动技能管理

public:
	::common::CListLink< Player >& player_link() { return player_link_; }
	::common::CListLink< Player > player_link_;

	virtual void SerialToJson(Json::Value& baseinfo);

	::common::CVector3 last_pos_;
};


